#include "Context.h"

#include "StateManager.h"
#include "DefaultState.h"
#include "AddPointState.h"
#include "../JSBridge.h"
#include "../model/Model.h"
#include "../view/MainWindow.h"

//--------------------------------------------------------------------------------
Context::Context()
{
    _jsBridge = new JSBridge();

    _model = new Model();

    _view = new MainWindow(this, _jsBridge);

    _stateManager = new StateManager();

    QObject::connect(_stateManager, SIGNAL(newStateAdded(AbstractState*)),
                                _view, SLOT(addNewState(AbstractState*)));

    QObject::connect(_jsBridge, SIGNAL(mapClicked(float, float)),
                     _stateManager, SLOT(mapClicked(float, float)));

    QObject::connect(_model, SIGNAL(onPointAdded(float, float)),
                     _view, SLOT(addPointToMap(float, float)));

    _stateManager->addNewState(new DefaultState(this));
    _stateManager->addNewState(new AddPointState(this));

    _view->show();

}

//--------------------------------------------------------------------------------
Context::~Context()
{
    delete _model;
    delete _stateManager;
    delete _jsBridge;
    delete _view;
}
//--------------------------------------------------------------------------------

StateManager* Context::getStateManager()
{
    return _stateManager;
}
//--------------------------------------------------------------------------------
Model* Context::getModel()
{
    return _model;
}
//--------------------------------------------------------------------------------
